package com.djk.diners.controller;

import com.djk.commons.model.domain.ResultInfo;
import com.djk.commons.model.dto.DinersDTO;
import com.djk.commons.utils.ResultInfoUtil;
import com.djk.diners.service.DinersService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "食客相关接口")
public class DinersController {

    @Resource
    private DinersService dinersService;
    @Resource
    private HttpServletRequest httpServletRequest;

    @PostMapping("register")
    public ResultInfo register(@RequestBody DinersDTO dinersDTO){
        return dinersService.register(dinersDTO,httpServletRequest.getServletPath());
    }

    /**
     * 检验手机号是否已注册
     *
     * @param phone
     * @return
     */
    @GetMapping("checkPhone")
    public ResultInfo checkPhone(String phone){
        dinersService.checkPhoneIsRegistered(phone);
        return ResultInfoUtil.buildSuccess(httpServletRequest.getServletPath());
    }

    /**
     * 登录
     * @param account
     * @param password
     * @return
     */
    @GetMapping("signin")
    public ResultInfo SignIn(String account,String password){
        return dinersService.signIn(account,password,httpServletRequest.getServletPath());
    }
}
